<?php

namespace app\admin\controller\mall;

use app\common\controller\AdminController;
use app\common\model\MallCommissionLevel;
use think\App;

class Commission extends AdminController
{
    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new MallCommissionLevel();
    }

    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames();
            $count = $this->model
                ->where($where)
                ->count();
            $list = $this->model
                ->where($where)
                ->page($page, $limit)
                ->order('id ASC')
                ->select();
            foreach($list as $k=>$v){
                if($v['ordermoney']>0){
                    $list[$k]['ordermoney'] ='一次性购买'.$v['ordermoney'].'元';
                }else{
                    $list[$k]['ordermoney']='--';
                }
                if($v['membercount']>0){
                    $list[$k]['membercount'] ='下级等级数达到'.$v['membercount'].'个';
                }else{
                    $list[$k]['membercount']='--';
                }
                if($v['sharepersont']>0){
                    $list[$k]['sharepersont'] =$v['sharepersont'].'折';
                }else{
                    $list[$k]['sharepersont']='--';
                }
                if($v['commission_againpersont']>0){
                    $list[$k]['commission_againpersont'] =$v['commission_againpersont'].'%';
                }else{
                    $list[$k]['commission_againpersont']='--';
                }
            }
            $data = [
                'code' => 0,
                'msg' => '',
                'count' => $count,
                'data' => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }



}